package com.assignwork.service.impl;

import com.assignwork.dto.TrainLoadLogDTO;
import com.assignwork.entity.TrainLoadLog;
import com.assignwork.mapper.TrainLoadLogMapper;
import com.assignwork.service.ITrainLoadLogService;
import com.assignwork.vo.TrainComprehensiveStatisticsVO;
import com.assignwork.vo.TrainLoadLogVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.common.utils.OfficeExportUtil;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.secure.BladeUser;
import org.springblade.system.cache.DictBizCache;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 火车装卸日志实现类
 */
@Service
public class TrainLoadLogServiceImpl extends BaseServiceImpl<TrainLoadLogMapper, TrainLoadLog> implements ITrainLoadLogService {

    @Override
    public IPage<TrainLoadLogVO> pageTrainLoadLog(BladeUser bladeUser, IPage<TrainLoadLogVO> page, TrainLoadLogDTO dto) {
        IPage<TrainLoadLogVO> res = baseMapper.pageTrainLoadLog(page, dto);
        for (TrainLoadLogVO record : res.getRecords()) {
            record.setLoadTypeName(DictBizCache.getValue("load_type", record.getLoadType()));
//            record.setWorkLineName(DictBizCache.getValue("work_line", record.getWorkLine()));
            record.setTimeSpaceName(DictBizCache.getValue("time_space", record.getTimeSpace()));
            record.setCoachTypeName(DictBizCache.getValue("train_typ_cod", record.getCoachType()));
            record.setWorkStatusName(DictBizCache.getValue("work_status", record.getWorkStatus()));
            record.setModifiedUserName(DictBizCache.getValue("modified_user", record.getModifiedUser()));
        }
        return res;
    }

    @Override
    public void trainLoadingExport(HttpServletResponse response, TrainLoadLogDTO dto) {
        List<TrainLoadLogVO> res = baseMapper.noPageTrainLoadLog(dto);
        for (TrainLoadLogVO record : res) {
            record.setLoadTypeName(DictBizCache.getValue("load_type", record.getLoadType()));
//            record.setWorkLineName(DictBizCache.getValue("work_line", record.getWorkLine()));
            record.setTimeSpaceName(DictBizCache.getValue("time_space", record.getTimeSpace()));
            record.setCoachTypeName(DictBizCache.getValue("train_typ_cod", record.getCoachType()));
            record.setWorkStatusName(DictBizCache.getValue("work_status", record.getWorkStatus()));
            record.setModifiedUserName(DictBizCache.getValue("modified_user", record.getModifiedUser()));
            if (record.getModifiedUserName()==null) {
                record.setModifiedUserName(record.getUpdateUserName());
            }
        }
        String title = "火车装卸日志";
        String fileName = "火车装卸日志";
        OfficeExportUtil.exportExcel(OfficeExportUtil.getWorkbook(title, "sheet1", TrainLoadLogVO.class, res), fileName, response);
    }

}